cc_library(
    name = "opentracing",
    srcs = glob(["src/**/*.cpp"], exclude=["src/dynamic_load_unsupported.cpp", "src/dynamic_load_windows.cpp"]),
    hdrs = glob(["include/opentracing/**/*.h"]) + [
        ":include/opentracing/config.h",
        ":include/opentracing/version.h",
    ],
    strip_include_prefix = "include",
    visibility = ["//visibility:public"],
    deps = [
      "//3rd_party:expected",
      "//3rd_party:variant",
    ],
    linkopts = [
      "-ldl",
    ],
)

genrule(
    name = "generate_version_h",
    srcs = glob([
        "*",
        "cmake/*",
        "src/**/*.cpp",
    ]),
    outs = [
      "include/opentracing/config.h",
      "include/opentracing/version.h"
    ],
    cmd = """
    TEMP_DIR=$$(mktemp -d)
    CONFIG_H_OUT=$${PWD}/$(location :include/opentracing/config.h)
    VERSION_H_OUT=$${PWD}/$(location :include/opentracing/version.h)
    OPENTRACING_ROOT=$$(dirname $${PWD}/$(location :CMakeLists.txt))
    cd $$TEMP_DIR
    cmake -DBUILD_TESTING=OFF -DBUILD_MOCKTRACER=OFF -L $$OPENTRACING_ROOT
    mv include/opentracing/config.h $$CONFIG_H_OUT
    mv include/opentracing/version.h $$VERSION_H_OUT
    rm -rf $$TEMP_DIR
    """,
)
